#!/bin/sh
"""": # -*-python-*-
bup_exec="$(dirname "$0")/bup-exec" || exit $?
exec "$bup_exec" "$0" ${1+"$@"}
"""

import os.path, sys

from bup.compat import argv_bytes, get_argvb
from bup.helpers import handle_ctrl_c, saved_errors
from bup.io import byte_stream
from bup import compat, metadata, options
import bup.xstat as xstat


optspec = """
ns-timestamp-resolutions TEST_FILE_NAME
--
"""

handle_ctrl_c()

o = options.Options(optspec)
opt, flags, extra = o.parse_bytes(get_argvb()[1:])

sys.stdout.flush()
out = byte_stream(sys.stdout)

if len(extra) != 1:
    o.fatal('must specify a test file name')

target = argv_bytes(extra[0])

open(target, 'w').close()
xstat.utime(target, (123456789, 123456789))
meta = metadata.from_path(target)

def ns_resolution(x):
    n = 1;
    while n < 10**9 and x % 10 == 0:
        x /= 10
        n *= 10
    return n

out.write(b'%d %d\n' % (ns_resolution(meta.atime),
                        ns_resolution(meta.mtime)))

if saved_errors:
    log('warning: %d errors encountered\n' % len(saved_errors))
    sys.exit(1)
